#include <stdint.h>

#ifndef __PSTWO_H
#define __PSTWO_H

#define CLOCK_PERIOD 5
#define DI   HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12) //PBin(12)           //PB12  输入

#define DO_H HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13,  GPIO_PIN_SET ) //PBout(13)=1        //命令位高
#define DO_L HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13,  GPIO_PIN_RESET ) //PBout(13)=0        //命令位低

#define CS_H HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,  GPIO_PIN_SET ) //PBout(14)=1       //CS拉高
#define CS_L HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,  GPIO_PIN_RESET ) //PBout(14)=0       //CS拉低

#define CLK_H HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15,  GPIO_PIN_SET ) //PBout(15)=1      //时钟拉高
#define CLK_L HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15,  GPIO_PIN_RESET ) //PBout(15)=0      //时钟拉低


//These are our button constants
#define PSB_SELECT      1
#define PSB_L3          2
#define PSB_R3          3
#define PSB_START       4
#define PSB_PAD_UP      5
#define PSB_PAD_RIGHT   6
#define PSB_PAD_DOWN    7
#define PSB_PAD_LEFT    8
#define PSB_L2         9
#define PSB_R2          10
#define PSB_L1          11
#define PSB_R1          12
#define PSB_GREEN       13
#define PSB_RED         14
#define PSB_BLUE        15
#define PSB_PINK        16
#define PSB_TRIANGLE    13
#define PSB_CIRCLE      14
#define PSB_CROSS       15
#define PSB_SQUARE      26

#define KEY_TOTAL_COUNT 16

//#define WHAMMY_BAR		8

//These are stick values
#define PSS_RX 5                //右摇杆X轴数据
#define PSS_RY 6
#define PSS_LX 7
#define PSS_LY 8

class Joystick {
public:
	Joystick();
	bool is_red_light(void);//判断是否为红灯模式
	void read_data(void);
	void send_cmd(uint8_t CMD);		  //
	void data_key(uint8_t* p_array_result);	  //键值读取
	uint8_t anolog_data(uint8_t button); //得到一个摇杆的模拟量
	void clear_data(void);	  //清除数据缓冲区
	void delay_us(uint32_t us) ;
	void vibration_mode(void);
	void exit_configing(void);
	void set_init(void);
	void vibration(uint8_t motor1, uint8_t motor2);
	void short_poll(void);
	void enter_configing(void);
	void turn_on_analog_mode(void);
	void debounce_button(uint8_t* p_array_result);

private:


  uint16_t Handkey;
  uint8_t Comd[2]={0x01,0x42};	//开始命令。请求数据
  uint8_t Data[9]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //数据存储数组
  uint16_t MASK[KEY_TOTAL_COUNT]={
      PSB_SELECT,
      PSB_L3,
      PSB_R3 ,
      PSB_START,
      PSB_PAD_UP,
      PSB_PAD_RIGHT,
      PSB_PAD_DOWN,
      PSB_PAD_LEFT,
      PSB_L2,
      PSB_R2,
      PSB_L1,
      PSB_R1 ,
      PSB_GREEN,
      PSB_RED,
      PSB_BLUE,
      PSB_PINK
  	};	//按键值与按键明

  //按键最后更新时间
  uint32_t key_last_ms[KEY_TOTAL_COUNT]={0};
};

#endif





